#ifndef _CONFIGURE_H_
#define _CONFIGURE_H_

#include <sys/types.h>
#include <pthread.h>
#include "common.h"

#define BUFF_LEN 1024
#define MAX_NODE_ENTRY 64

struct cache_node
{
	u_int32_t ip;
	int state; /* 0 for down, 1 for present */
#define ST_DOWN 0
#define ST_PRESENT 1
	int total_av;
	int weight; /* used by select_master_cache()
				if should_go_public() return 0, it is set to 0 */
	struct system_info sys_info;
};

struct configure
{
	char buff_node[BUFF_LEN];
	int nr_cache;
	char *node_str[MAX_NODE_ENTRY];
	struct cache_node cache_list[MAX_NODE_ENTRY];
	int total_weight; /* total weigth in all cache, used by select_master_cache() */
};


int load_configure(struct configure *configure);
int update_cache_state(struct configure *configure);
int select_master_cache(struct configure *configure);
int select_master_cache_r(struct configure *configure, pthread_mutex_t *lock);
void weigth_algorithm(struct configure *configure);
#endif
